import easyocr
from PIL import Image
import numpy as np

model_storage_directory = "./models"
user_network_directory = "./models"

reader = easyocr.Reader(
    ["ch_sim", "en"],
    model_storage_directory=model_storage_directory,
    user_network_directory=user_network_directory,
)

# 打开图片
image = Image.open("test.png")

# 设定要裁剪的区域，(左上角x, 左上角y, 右下角x, 右下角y)
crop_area = (0, 0, 100, 100)

# 裁剪图片
cropped_image = image.crop(crop_area)

# https://www.jaided.ai/easyocr/documentation/
result = reader.readtext(
    np.array(cropped_image),  # 参数放进去
    # allowlist="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
    detail=0,
    paragraph=True,
)

print(result)
